package mx.com.theboard.client;

import com.google.gwt.event.dom.client.BlurEvent;
import com.google.gwt.event.dom.client.BlurHandler;
import com.google.gwt.event.dom.client.FocusEvent;
import com.google.gwt.event.dom.client.FocusHandler;
import com.google.gwt.user.client.ui.FocusWidget;
import com.google.gwt.user.client.ui.TextBoxBase;
import com.google.gwt.user.client.ui.ValueBoxBase;
import com.google.gwt.user.client.ui.Widget;

public class Utils {
	public static void addPlaceHolder(final Widget w, final String placeholder){
    	((FocusWidget) w).addBlurHandler(new BlurHandler() {				
			@Override
			public void onBlur(BlurEvent event) {
				if(((TextBoxBase) w).getValue().equals(" ") || ((TextBoxBase) w).getValue().equals("")){
					((ValueBoxBase<String>) w).setValue(placeholder);
				}					
			}
		});
    	((FocusWidget) w).addFocusHandler(new FocusHandler() {
			
			@Override
			public void onFocus(FocusEvent event) {
				if(((TextBoxBase) w).getValue().equals(placeholder)){
					((ValueBoxBase<String>) w).setValue("");
				}
				
			}
		});
    }
}
